﻿using System;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;

public class DebugTools
{
    Stopwatch timer;

	public DebugTools()
	{
        // Establish timer on class initialisation.
        timer = new Stopwatch();
   	}

    /// <summary>
    /// Starts a high resolution stopwatch timer to test performance.
    /// </summary>
    /// <returns></returns>
    public void startTimer()
    {
        timer.Start();      
    }

    /// <summary>
    /// Writes a checkpoint into the output file, along with a snapshot of the timer at that moment.
    /// </summary>
    /// <param name="checkPointLabel"></param>
    /// <param name="filename"></param>
    public void writeTimerCheckPoint(string checkPointLabel, string filename)
    {
        StreamWriter fileOutput = new StreamWriter(Environment.CurrentDirectory + filename + ".log");
        fileOutput.WriteLine(string.Format("[{0}] - {1}", timer.Elapsed, checkPointLabel));
        fileOutput.Close();
    }

    /// <summary>
    /// Stops the timer! TODO: Overload to indicate output to file or message box (append mode for file).
    /// </summary>
    /// <returns></returns>
    public void stopTimer()
    {
        timer.Stop();
        MessageBox.Show(string.Format("Elapsed Time: {0}", timer.Elapsed));
        timer.Reset();
    }

    /// <summary>
    /// Saves a file to current directory filename.log
    /// </summary>
    /// <param name="fileName"></param>
    public void stopTimer(string fileName)
    {
        timer.Stop();
        StreamWriter fileOutput = new StreamWriter(Environment.CurrentDirectory + fileName + ".log");
        fileOutput.WriteLine(string.Format("[{0}] - Timer Stopped", timer.Elapsed));
        fileOutput.Close();
        timer.Reset();
    }

}
